<?php
/**
 * SocialEngine
 *
 * @category   Application_Extensions
 * @package    Flashgame
 * @version    $Id: Core.php 6852 2010 YouNet $
 * @author     To Anh
 */
                     
class Flashgame_Plugin_Core
{
  public function onStatistics($event)
  {
    $table   = Engine_Api::_()->getDbTable('flashgames', 'flashgame');
    $select = new Zend_Db_Select($table->getAdapter());
    $select->from($table->info('name'), 'COUNT(*) AS count');
    $event->addResponse($select->query()->fetchColumn(0), 'games');
  }

  public function onUserDeleteBefore($event)
  {
    $payload = $event->getPayload();
    if( $payload instanceof User_Model_User ) {
      // Delete flashgames
      $flashgameTable = Engine_Api::_()->getDbtable('flashgames', 'flashgame');
      $flashgameSelect = $flashgameTable->select()->where('owner_id = ?', $payload->getIdentity());
      foreach( $flashgameTable->fetchAll($flashgameSelect) as $flashgame ) {
        $flashgame->delete();
      }
    }
  }
}